//
//  CZStatusOriginalView.swift
//  微博08
//
//  Created by 1 on 16/3/13.
//  Copyright © 2016年 cjf. All rights reserved.
//

import UIKit

let CZStatusCellMargin: CGFloat = 8

// 封装用户信息和微博文本
class CZStatusOriginalView: UIView {
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = UIColor.whiteColor()
        
        prepareUI()
    }
    
    private func prepareUI() {
        // 1.添加子控件
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(memberView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(verifiedTypeImage)
        addSubview(contentLabel)
        
        // 2.添加约束
        // 头像
        iconView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self).offset(CZStatusCellMargin)
            make.top.equalTo(self).offset(CZStatusCellMargin)
            make.size.equalTo(CGSize(width: 35, height: 35))
        }
        
        // 用户名称
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView)
            make.leading.equalTo(iconView.snp_trailing).offset(CZStatusCellMargin)
        }
        
        // 时间
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(iconView.snp_trailing).offset(CZStatusCellMargin)
            make.bottom.equalTo(iconView)
        }
        
        //来源
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(timeLabel.snp_trailing).offset(CZStatusCellMargin)
            make.centerY.equalTo(timeLabel)
        }
        
        // 微博内容
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView.snp_bottom).offset(CZStatusCellMargin)
            make.leading.equalTo(self).offset(CZStatusCellMargin)
            make.trailing.equalTo(self).offset(-CZStatusCellMargin)
        }
        
        // 会员等级
        memberView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(nameLabel.snp_trailing).offset(CZStatusCellMargin)
            make.centerY.equalTo(nameLabel)
            make.size.equalTo(CGSize(width: 14, height: 14))
        }
        
        // 认证
        verifiedTypeImage.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_trailing)
            make.centerY.equalTo(iconView.snp_bottom)
        }
        
    }

    
    // MARK: - 懒加载
    // 头像
    private lazy var iconView: UIImageView = UIImageView(image: (UIImage(named: "avatar")))
    
    // 用户名称
    private lazy var nameLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), font: 14)
    
    // 会员等级
    private lazy var memberView: UIImageView = UIImageView(image: nil)
    
    // 时间
    private lazy var timeLabel: UILabel = UILabel(textColor: UIColor.orangeColor(), font: 11)
    
    // 来源
    private lazy var sourceLabel: UILabel = UILabel(textColor: UIColor.lightGrayColor(), font: 11)
    
    // 认证
    private lazy var verifiedTypeImage: UIImageView = UIImageView(image: nil)
    
    // 微博内容的Label
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), font: 15)
    
}
